<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    private $_config;

    /**
     * leitura de variaveis passadas no application.ini
     */
    public function _initLoadParamsApplication()
    {
        $this->_config = new Zend_Config_Ini('../application/configs/application.ini', APPLICATION_ENV);
        
        $registry = Zend_Registry::getInstance();
        $registry->set("nomeempresa", $this->_config->site->nomeempresa);
        $registry->set("nomesistema", $this->_config->site->nomesistema);
        $registry->set("versaosistema", $this->_config->site->version);
        $registry->set("urlalfresco", $this->_config->alfresco->url);
        $registry->set("folderview", $this->_config->alfresco->folderview);
    }

    /**
     * require de classes necessarias ao funcionamento do sistema
     * @return Zend_Application_Module_Autoloader
     */
    protected function _initAutoloader()
    {
        # load controller base in /application/controllers
        Zend_Loader::loadClass('BaseController', '../application/controllers');

        # load AuthAdapter in /library
        Zend_Loader::loadClass('AuthAdapter', '../application/library');

        # load Api Alfresco in /library
        $autoloader = new Zend_Application_Module_Autoloader(
                array(
                    'namespace' => '',
                    'basePath' => APPLICATION_PATH,
                    'resourceTypes' => array(
                        'alfresco' => array('path' => 'library/Alfresco/', 'namespace' => 'Alfresco'),
                        'ged' => array('path' => 'library/Ged', 'namespace' => 'Ged')
                        )
                )
        );

        return $autoloader;
    }

    /**
     * carregamento de plugins
     * @param array $options
     */
    protected function _initPlugins()
    {
        # get new session
        $auth = Zend_Auth::getInstance()
            ->setStorage(new Zend_Auth_Storage_Session('Zend_Auth_Share'));

        # load plugin of auth controllers
        $auth = Zend_Controller_Front::getInstance()
            ->registerPlugin(new Plugin_Auth($auth));
    }

    /**
     * configuracao de doctype do layout
     */
    protected function _initDoctype()
    {
        $view = new Zend_View();

        // Carrega DocType
        $view->doctype('XHTML1_STRICT');

        // Carrega Meta
        $view->headMeta()
            ->appendHttpEquiv('pragma', 'no-cache')
            ->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
            ->appendHttpEquiv('Content-Language', 'pt-br');

        // Carrega Título
        $view->headTitle($this->_config->site->nomesistema);

        // Carrega CSS
        $view->headLink()
            ->appendStylesheet('css/ui/jquery-ui.css', 'all')
            ->appendStylesheet('css/reset.css')
            ->appendStylesheet('css/forms.css')
            ->appendStylesheet('css/simple-modal.css')
            ->appendStylesheet('css/datePicker.css')
            ->appendStylesheet('css/estilo.css')
//            ->appendStylesheet('/css/jquery.countdown.css')
            ->appendStylesheet('css/treeview/jqueryFileTree.css', 'all')
            ->appendStylesheet('css/print.css', array('media' => 'print'))
            ->appendStylesheet('css/tema.css');

        // Carrega JS
        $view->headScript()
            ->appendFile('js/jquery.js')
            ->appendFile('js/jquery-ui.js')
            ->appendFile('js/sammy.js')
            ->appendFile('js/jquery.validate.js')
            ->appendFile('js/jquery.countdown.js')
            ->appendFile('js/treeview/jqueryFileTree.js')
            ->appendFile('js/base.js');
    }

    /**
     * configuracao de rotas
     */
    public function _initRoutes()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();

        $route = new Zend_Controller_Router_Route_Static(
                'login',
                array('controller' => 'Auth', 'action' => 'login')
        );

        $router->addRoute('login', $route);
    }

}
